/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Modelo;

import java.io.Serializable;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

/**
 *
 * @author Alex
 */
public class ModelEvaluacion implements Serializable{


    private Conection con = new Conection();
    private ResultSet rs;

    public ModelEvaluacion(Conection con) {
        this.con = con;
    }

    public ResultSet getRs() {
        return rs;
    }

    public void setRs(ResultSet rs) {
        this.rs = rs;
    }

public LinkedList Evaluaciones(String codigo,String parame )throws SQLException{
	LinkedList listaEntre=new LinkedList();
	PreparedStatement pstmt=null;
	ResultSet rs=null;
  	try{
                     if(parame.equalsIgnoreCase("Bacante")){
                          pstmt=con.getCon().prepareStatement("select * from evaluado where evaluado.Bacante =" +"'"+ codigo +"'");
            }else if(parame.equalsIgnoreCase("Codigo")){
                 pstmt=con.getCon().prepareStatement("select * from evaluado where evaluado.Codigo =" +"'"+ codigo +"'");
            }
                      rs=pstmt.executeQuery();
  		while(rs.next()){
  			listaEntre.add(Evaluacion.Load(rs));

  		}
  	}finally{
 		if(rs!=null){
			rs.close();
		}
		if(pstmt!=null){
			pstmt.close();
			pstmt=null;
		}
	}

	return listaEntre;
 }
  public void setNewEvaluado(Evaluacion pr) throws SQLException {
        if( !con.isConnect())
                throw new SQLException("no Hay Conexion");
            PreparedStatement pstmt=null;
            try{
                pstmt=con.getCon().prepareStatement("insert into evaluado values(?,?,?,?,?)");
              pstmt.setString(1, pr.getAspirante());
               pstmt.setString(2, pr.getEntrevista());
               pstmt.setString(3, pr.getAspirante());
               pstmt.setDouble(4, pr.getTotal());
               pstmt.setString(5, pr.getBacante());
		pstmt.executeUpdate();

                }finally
                {
                    if( pstmt!=null )
                    pstmt.close();
                }


    }
    public boolean Eliminar(String codigo) throws Exception
      {

    try {
         Class.forName("com.mysql.jdbc.Driver").newInstance();

         if (con.isConnect())
         {
             PreparedStatement stmt = con.getCon().prepareStatement("delete from evaluado where Codigo= "+codigo);
               stmt.executeUpdate();
                return true;

            }
    }
    catch(SQLException ex) {
         System.out.println(ex);
    }
    catch(ClassNotFoundException ex) {
    System.out.println(ex);  }
    return false;
    }
     public boolean Existe( String codigo ) throws SQLException{
            if( !con.isConnect() )
                    throw new SQLException("no conexion");
            boolean sw=true;
            PreparedStatement pstmt=null;
            ResultSet rs=null;
            try{

                            pstmt=con.getCon().prepareStatement("select count(*) from evaluado where codigo=?");

                    pstmt.setString(1,codigo);
                    rs=pstmt.executeQuery();

                    if(rs.next()){
                        if(String.valueOf(rs.getString(1)).equals("0"))
                            sw=false;
                    }
            }finally{
                    if(rs!=null)
                            rs.close();

                    if(pstmt!=null)
                            pstmt.close();
            }
            return sw;
    }

}// fin clase model
